package com.example.clickcheck;
import static java.lang.Thread.sleep;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.res.TypedArrayUtils;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import com.google.android.gms.common.util.ArrayUtils;
import java.util.Arrays;
import java.util.Timer;
import java.util.TimerTask;

public class MainActivity extends AppCompatActivity {
    long[] timeInfo;
    String str;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        timeInfo = new long[10];

        Button button1 = (Button)findViewById(R.id.button);
        Button button2 = (Button)findViewById(R.id.button2);

        button1.setOnClickListener(new MyButton1());
        button2.setOnClickListener(new MyButton2());
    }

    public class MyButton1 implements View.OnClickListener{
//        long[] timeInfo = new long[10];
        TextView tv = (TextView)findViewById(R.id.textView);
        TextView ts = (TextView)findViewById(R.id.textView2);
//        Button button1 = (Button)findViewById(R.id.button);
        int i = 0;
        @Override
        public void onClick(View v) {
//            long[] timeInfo = new long[10];
            if( i < 10){
//                if(event.getAction() == MotionEvent.ACTION_UP) {
//                button1.callOnClick();
                timeInfo[i] = System.currentTimeMillis();
                tv.setText("You have tapped "+ (i+1) + " times");
                ts.setText("Current TimeStamp: "+String.valueOf(timeInfo[i]));
                i += 1;
            }
            if( i >= 10){
                Button bt = (Button)findViewById(R.id.button);
                bt.setBackgroundColor(Color.rgb(251,206,3));
                bt.setText("Checking...");
//                getSimilarityRatio
//                Timer timer = new Timer();
//                timer.schedule(new TimerTask() {
//                    @Override
//                    public void run() {
//                        //延时执行事件
////                        str = String.valueOf(timeInfo[0]);
////
////                        for (int i = 1; i < 10; i++) {
////                            str += String.valueOf(timeInfo[i]);
////                        }
////
////                        Intent sendIntent = new Intent();
////                        sendIntent.setAction(Intent.ACTION_SEND);
////                        sendIntent.putExtra(Intent.EXTRA_TEXT, str);
////                        sendIntent.setType("text/plain");
////
////                        Intent shareIntent = Intent.createChooser(sendIntent, null);
////                        startActivity(shareIntent);
//
//                        str = String.valueOf(timeInfo[0] + '\n');
//                        str += '\n';
//                        for (int i = 1; i < 10; i++) {
//                            str += (String.valueOf(timeInfo[i]) + '\n');
//                        }
////                TextView t3 = (TextView)findViewById(R.id.textView3);
////                        bt.setText(str);
//                        // 随机版本
//                        if(timeInfo[9] % 2 == 0 || timeInfo[9] % 3 == 0 || timeInfo[9] % 5 == 0 || timeInfo[9] % 7 == 0){
//                            bt.setBackgroundColor(Color.rgb(83,179,93));
//                            bt.setText("Successful!");
//                            bt.setText(str);
//
//                        }else {
//                            bt.setBackgroundColor(Color.rgb(254,53,0));
//                            bt.setText("Failed!");
//                            bt.setText(str);
//                        }
//                        //成功版本
////                        bt.setBackgroundColor(Color.rgb(83,179,93));
////                        bt.setText("Successful!");
//                        //失败版本
////                        bt.setBackgroundColor(Color.rgb(254,53,0));
////                        bt.setText("Failed!");
//
//                    }
//                }, 3500); //时间单位为毫秒
//                str = String.valueOf(timeInfo[0] + '\n');
//                for (int i = 1; i < 10; i++) {
//                    str += (String.valueOf(timeInfo[i]) + '\n');
//                }
////                TextView t3 = (TextView)findViewById(R.id.textView3);
//                bt.setText(str);
            }
        }
    }

    private class MyButton2 implements View.OnClickListener{

        @Override
        public void onClick(View v) {
            Button b = (Button)findViewById(R.id.button2);
            b.setVisibility(View.INVISIBLE);
        }
    }
}